##################################################################
# File : /lua/ui/game/lobbyui.lua
# Description : Game UI
# Author : GPG / Neruz
##################################################################

local UIUtil = import('/lua/ui/uiutil.lua')
local LayoutHelpers = import('/lua/maui/layouthelpers.lua')
local GameMain = import('/lua/ui/game/gamemain.lua')
local Group = import('/lua/maui/group.lua').Group
local Bitmap = import('/lua/maui/bitmap.lua').Bitmap
local GameCommon = import('/lua/ui/game/gamecommon.lua')

local gameParent = nil

function OnFirstUpdate()
    EnableWorldSounds()
end

function CreateGameControls()
    gameParent = UIUtil.CreateScreenGroup(GetFrame(0), "GameMain ScreenGroup")

    gameParent:SetNeedsFrameUpdate(true)
    gameParent.OnFrame = function(self, deltaTime)
        gameParent:SetNeedsFrameUpdate(false)
        OnFirstUpdate()
    end

    local worldView = import('/lua/ui/game/worldview.lua').Create()
    LayoutHelpers.FillParent(worldView,gameParent)
    worldView:SetParent(gameParent)

    gameParent.worldView = worldView
    local WidthOffset = UIUtil.GetOffsets()
    local TopInOffset = 17

    DefineRange('rangeDefault','/textures/ui/common/game/rangerings/range_ring.dds',0.5,'/textures/particles/ring/rn_0005_44.dds',0.5)
end

function Create(isReplay)
    local prefetchTable = { models = {}, anims = {}, d3d_textures = {}, batch_textures = {} }

    # update loc table with player's name
    local focusarmy = GetFocusArmy()
    if focusarmy >= 1 then
        LocGlobals.PlayerName = GetArmiesTable().armiesTable[focusarmy].nickname
    end

    GameCommon.InitializeUnitIconBitmaps(prefetchTable.batch_textures)

    CreateGameControls()
end

function Destroy()
    if gameParent then
        gameParent:Destroy()
        gameParent = nil
    end
end
